#include "SocketLinkCmd.h"
#include"msc.h"


#define  SlaveName "1"


SocketLinkCmd::SocketLinkCmd(QObject *parent)
{
}

SocketLinkCmd::~SocketLinkCmd()
{

}

QStringList SocketLinkCmd::ReadShortRegister(QString stratAddr,int Num)
{
	QString text = "RDS " + stratAddr + ".S "+ QString::number(Num)+"\r";
	std::string str = GetmscInstance()->SendRecvDataFlag("PLC", text.toLocal8Bit().data());
	QString qstr = str.c_str();
	QStringList strList = qstr.split(" ");
	return strList;
}

QStringList SocketLinkCmd::ReadMR(QString stratAddr, int Num)
{
	QString text = "RDS " + stratAddr + " " + QString::number(Num) + "\r";
	std::string str = GetmscInstance()->SendRecvDataFlag("PLC", text.toLocal8Bit().data());
	QString qstr = str.c_str();
	QStringList strList = qstr.split(" ");
	return strList;
}

QString SocketLinkCmd::WriteShortRegister(QString stratAddr, QString strData)
{
	QStringList strList = strData.split(" ");
	QString text = "WRS " + stratAddr + ".S " + QString::number(strList.size()) +" "+ strData + "\r";
	std::string str = GetmscInstance()->SendRecvDataFlag("PLC", text.toLocal8Bit().data());
	QString qstr = str.c_str();
	return qstr.replace("\r\n","");
}

QString SocketLinkCmd::WriteLongRegister(QString stratAddr, QString strData)
{
	QStringList strList = strData.split(" ");
	QString text = "WRS " + stratAddr + ".L " + QString::number(strList.size()) + " " + strData + "\r";
	std::string str = GetmscInstance()->SendRecvDataFlag("PLC", text.toLocal8Bit().data());
	QString qstr = str.c_str();
	return qstr.replace("\r\n", "");
}


